package com.xbts.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.xbts.common.annotation.Excel;
import com.xbts.common.enums.ServerStatusEnum;
import com.xbts.common.enums.ShoppingCarEnums;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.core.domain.BaseEntity;

import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * 用户-弹性云服务器关系对象 cn_user_cloud_servers_relation
 *
 * @author xbts
 * @date 2023-08-03
 */
@Data
@ApiModel("用户-弹性云服务器关系对象")
@TableName("cn_user_cloud_servers_relation")
public class CnUserCloudServersRelation extends BaseEntity {

private static final long serialVersionUID=1L;

    /** 主键 */
    @TableId
    @JsonSerialize(using= ToStringSerializer.class)
    private Long id;

    /** 用户id */
    @ApiModelProperty("用户id")
    private Long userId;

    /** 弹性云服务器id/政务云/云市场id */
    @ApiModelProperty("弹性云服务器id/政务云/云市场id")
    private String relationId;

    /** 是否自动续费，默认不自动续费 */
    @ApiModelProperty("是否自动续费，默认不自动续费")
    private Boolean autoRenew;

    /** 购买方式（0按次 1按天 30按月 365按年） */
    @ApiModelProperty("购买方式（0按次 1按天 30按月 365按年）")
    private Integer periodType;

    /** 购买的期限数量 */
    @ApiModelProperty("购买的期限数量")
    private Integer periodNum;

    /** 修改价格 */
    @Excel(name = "修改价格")
    @ApiModelProperty("修改价格")
    @NotEmpty(message = "修改价格不能为空")
    private BigDecimal updatePrice;

    /** 原始价格 */
    @Excel(name = "原始价格")
    @ApiModelProperty("原始价格")
    @NotEmpty(message = "原始价格不能为空")
    private BigDecimal originalPrice;

    /** 优惠的金额 */
    @Excel(name = "优惠的金额")
    @ApiModelProperty("优惠的金额")
    @NotEmpty(message = "优惠的金额不能为空")
    private BigDecimal discountPrice;

    /** 过期时间 */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("过期时间")
    private Date expirationTime;

    /** 购买时间/续费时间 */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("购买时间/续费时间")
    private Date buyingTime;

    /**
     * 购物车类型
     */
    private ShoppingCarEnums shoppingCarEnums;

    /**
     *  订单摘要
     */
    private String orderAbstract;
    /**
     *  描述
     */
    private String remark;

    /**
     * ServerStatusEnum 状态（ACTIVE运行中 SHUTOFF已停止 DELETED已删除 EXPIRED已到期）
     */
    private ServerStatusEnum status;

    /**
     * 云市场sku
     */
    private Long marketSkuId;

    /** 项目id */
    private String regionId; // 在购物车中支付时赋值的

    /** 子订单ID */
    private String orderItemId; // 子订单ID

    /**
     * 价格查询对象JSON字符串
     */
    private String priceQueryJsonStr;

    /**
     * 共计已购买多少月份
     */
    private Integer months;
    /** 规格实付款 */
    private BigDecimal ec2Price;
    /** 磁盘实付款 */
    private BigDecimal ebsPrice;
    /** 带宽实付款 */
    private BigDecimal vpcPrice;
    /** 总付款 */
    private BigDecimal totalPrice;
    /**
     * 云服务器json
     */
    // 忽略json序列化
    @JsonIgnore
    private String jsonStr;

    @TableField(exist = false)
    private String cloudServerJsonStr;

    @TableField(exist = false)
    private Double price;

    @TableField(exist = false)
    @JsonIgnore
    private Integer expirationDay;
    @TableField(exist = false)
    private String ip;
    @TableField(exist = false)
    private String nickName;
    @TableField(exist = false)
    private String serversJsonStr;
    @TableField(exist = false)
    private int offset;

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(userId),"user_id",userId);
        queryWrapper.eq(!Objects.isNull(relationId),"relation_id",relationId);
        queryWrapper.eq(!Objects.isNull(autoRenew),"auto_renew",autoRenew);
        queryWrapper.eq(!Objects.isNull(periodNum),"period_num",periodNum);
        queryWrapper.eq(!Objects.isNull(expirationTime),"expiration_time",expirationTime);
        queryWrapper.eq(!Objects.isNull(buyingTime),"buying_time",buyingTime);
        return queryWrapper;
    }
}